const chatBox = document.getElementById('chatBox');
const userInput = document.getElementById('userInput');
const modles=document.getElementById('modles');
var box=document.querySelector('.box');
box.addEventListener("click", function () {
 userInput.value=box.textContent
});
// 发送用户消息并获取回复
function sendMessage() {

  const userMessage = userInput.value;
  if (userMessage.trim() === '') return;
  
  // 显示用户消息
  const userDiv = document.createElement('div');
  userDiv.classList.add('user-message');
  userDiv.textContent = userMessage;
  chatBox.appendChild(userDiv);


  const hisuserDiv = document.createElement('div');
  hisuserDiv.classList.add('box');
  hisuserDiv.textContent = userMessage;
  modles.appendChild(hisuserDiv);

let answer
const message = document.getElementById('userInput').value;
fetch('http://127.0.0.1:5000/post', {
    method: 'POST',
    headers: {
          'Content-Type': 'application/json'
      },
    body: JSON.stringify({ message: message })
  })
  .then(response => response.json())
  .then(data => {
      console.log('Success:', data);
    answer=data.answer
    const botMessage =answer
  // 显示机器人回复
const botDiv = document.createElement('div');
botDiv.classList.add('bot-message');
botDiv.textContent = botMessage;
chatBox.appendChild(botDiv);
    })
  .catch((error) => {console.error('Error:', error);});




  // 清空输入框
userInput.value = '';
}
// 获取机器人回复（这里是一个简单的示例）
